﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Data.SQLite;

namespace LiteQueryWPF.FuncPanelHelper
{
    public class FuncPanel : Interfaces.IFuncPanel
    {
        public Tuple<bool, Exception> ExportToExcel(DataTable data, string path)
        {
            return SqlFuncHelper.AsposeHelper.ExportDataTableToExcel(data, path);
        }

        public DataSet Query(string dbpath, string sql)
        {
            try
            {
                using (SQLiteConnection conn = new SQLiteConnection(dbpath))
                {
                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        conn.Open();
                        cmd.Connection = conn;
                        SQLiteHelper sh = new SQLiteHelper(cmd);
                        var dt = sh.Select(sql);
                        var ds = new DataSet();
                        ds.Tables.Add(dt);
                        return ds;
                    }
                }
            }
            catch (Exception ex){
                LogHelper.Error(ex.Message,ex);
                return null;
            }
        }
    }
}
